package com.xn.app.muying.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.bean.OrderDetailBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/12/1.
 */
public class OrderDetailVIPAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<OrderDetailBean> list = new ArrayList<>();

    public OrderDetailVIPAdapter(Context context) {
        super();
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void getData(ArrayList<OrderDetailBean> data) {
        this.list.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.orderdetailvip_item, null);
            holder = new ViewHolder();
            holder.tv_ordernumber = (TextView) view.findViewById(R.id.ordernumber_tv);
            holder.tv_service = (TextView) view.findViewById(R.id.service_tv);
            holder.tv_viptime = (TextView) view.findViewById(R.id.viptime_tv);
            holder.tv_pay = (TextView) view.findViewById(R.id.pay_tv);
            holder.tv_payway = (TextView) view.findViewById(R.id.payway_tv);
            holder.tv_paytime = (TextView) view.findViewById(R.id.paytime_tv);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_ordernumber.setText("订单号：" + list.get(i).getOrderNumber());
        holder.tv_service.setText("服务项目：" + list.get(i).getServiceProductName());
        if(list.get(i).getTotalServiceCount().equals("12")){
            holder.tv_viptime.setText("会员时间：" + list.get(i).getTotalServiceCount()+"月");
        }else{
            holder.tv_viptime.setText("会员时间：" + list.get(i).getTotalServiceCount()+"天");
        }
        holder.tv_pay.setText("费用：" + list.get(i).getOrderPrice()+"元");
        holder.tv_payway.setText("支付方式：" + list.get(i).getPayMethodDescription());
        String[] strs = list.get(i).getCreationTime().split("T");
        String[] strs2 = strs[1].split(":");
        holder.tv_paytime.setText("下单时间：" + strs[0] + " " + strs2[0] + ":" + strs2[1]);
        return view;
    }

    class ViewHolder {
        TextView tv_ordernumber, tv_service,
                tv_viptime, tv_pay, tv_payway, tv_paytime;
    }
}
